<template>
  <div class="addresslistmodule">
    <van-address-list
      class="addresslist"
      v-model="AddressId"
      :list="areaLists"
      :disabled-list="disabledList"
      :disabled-text="disabledList.length>0?'以下地址超出配送范围':''"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
      @select="onSelect">
    </van-address-list>
  </div>
</template>

<script>
// import http from 'axios'
import { mapState, mapActions } from 'vuex'
import Vue from 'vue'
import { AddressList } from 'vant'
Vue.use(AddressList)

export default {
  data () {
    return {
    }
  },
  computed: {
    ...mapState('addressModule', ['areaLists', 'chosenAddressId', 'disabledList']),
    AddressId: {
      get: function () {
        return this.chosenAddressId
      },
      set: function () {

      }
    }
  },
  methods: {
    ...mapActions('addressModule', ['getAddressAction', 'modifyArea']),
    onAdd () {
      this.$router.push({ name: 'Address-edit' })
    },
    onEdit (item, index) {
      this.$router.push({ name: 'Address-edit', params: { editType: item.id } })
    },
    onSelect (item, index) {
      if (!item.isDefault) {
        this.modifyArea(item)
      }
    }
  },
  mounted () {
    // console.log(this.$route)
    // if (sessionStorage.userInfo) {
    //   const token = JSON.parse(sessionStorage.userInfo).token
    //   if (token) {
    //     content.addressDetail = this.addressDetail
    //     content.user = token
    //     content.id = 'area' + new Date().getTime()
    //     content.address = (content.province.substr(0, 2) === content.city.substr(0, 2) ? content.city : content.province + content.city) + content.county + ' ' + this.addressDetail
    //   }
    // }
    this.getAddressAction()
  }
}
</script>

<style lang="scss" scoped>
.addresslistmodule{
  // .van-address-list{
  //   margin: .09rem 0;
  //   height: 11rem;
  //   overflow-y: auto;
  // }
}
</style>
